package com.hyl.domain.trade.service.settlement.filter;

import com.hyl.domain.trade.adapter.repository.ITradeRepository;
import com.hyl.domain.trade.model.entity.TradeSettlementRuleCommandEntity;
import com.hyl.domain.trade.model.entity.TradeSettlementRuleFilterBackEntity;
import com.hyl.domain.trade.service.settlement.factory.TradeSettlementRuleFilterFactory;
import com.hyl.types.design.framework.link.moudle2.handler.ILogicHandler;
import com.hyl.types.enums.ResponseCode;
import com.hyl.types.exception.AppException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author hyl
 * @description SC黑名单管控过滤DCCService配置的属性scBlacklist
 * @create 2025-07-04 17:16
 */
@Slf4j
@Service
public class SCRuleFilter implements ILogicHandler<TradeSettlementRuleCommandEntity, TradeSettlementRuleFilterFactory.DynamicContext, TradeSettlementRuleFilterBackEntity> {

    @Resource
    private ITradeRepository repository;

    @Override
    public TradeSettlementRuleFilterBackEntity apply(TradeSettlementRuleCommandEntity requestParameter, TradeSettlementRuleFilterFactory.DynamicContext dynamicContext) throws Exception {
        log.info("结算规则过滤-渠道黑名单校验{} outTradeNo:{}", requestParameter.getUserId(), requestParameter.getOutTradeNo());
        //sc黑名单拦截
        boolean intercept = repository.isSCBlackIntercept(requestParameter.getSource(),requestParameter.getChannel());
        if ( intercept){
            log.error("SC渠道黑名单拦截");
            throw new AppException(ResponseCode.E0105);
        }
        return next(requestParameter, dynamicContext);
    }
}
